#pragma once

namespace Tmpl {

class Entity;
class EntityUnitStats
{
public:
	enum UnitCondition
	{
		UNIT_CONDITION_ALIVE		= 1,
		UNIT_CONDITION_DEAD			= 1 << 1,
	};

	Entity* GetOwner(){return mOwner;}

	// HP
	float GetHP() const {return mHP;}
	float GetHPMax() const {return mHPMax;}
	float GetHPPercent() const { return Max(0.0f,Min(100.0f,mHP * 100.0f / mHPMax));}
	void AddHP(float hp, int entitySource);

	// Condition
	void ConditionSetFlags(int flag){mConditionFlags = flag; }
	void ConditionAddFlag(int flag){mConditionFlags |= flag; }
	void ConditionRemoveFlag(int flag){mConditionFlags &= ~flag; }
	bool ConditionHasFlag(int flag) const {return ((mConditionFlags & flag) == flag);}
	int ConditionGetFlags() const {return mConditionFlags; }

	bool IsDead() const { return ConditionHasFlag(UNIT_CONDITION_DEAD); }
private:
	friend class EntityUnitStatSystem;

	Entity* mOwner;
	int mConditionFlags;

	float mHP, mHPMax;
};

struct UnitData;
class EntityUnitStatSystem
{
public:
	static void Init();
	static void Clear();

	static int NewStats(Entity* owner, const UnitData& data);
	static void RemoveStats(int id);
	static EntityUnitStats* GetStats(int id);

	static JobHandle Update(JobHandle dependency);

private:
	static void UpdateStatsChunk(int chunk);
};

} // namespace Tmpl